var apiHost = wx.getStorageSync("apiHost"); //请求地址
var Appid = wx.getStorageSync('Appid');
var Secret = wx.getStorageSync('Secret');

var AppidFlag = wx.getStorageSync('AppidFlag');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userinfo: '',      //用户信息
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var token = wx.getStorageSync('token');             //用户的token信息

    that.setData({
      token: token
    })

    that.initPersonal(token)

  },

  /**
   * 初始化个人中心
   */
  initPersonal: function (token){
    var that = this;

    wx.showLoading({
      title: '加载中',
      icon: 'loading',
    });

    wx.request({
      url: apiHost + "/mobile/users/index", //仅为示例，并非真实的接口地址
      data: {
        token: token,
        appId: AppidFlag
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        var code = res.data.code;
        var msg = res.data.msg;

        if (code == "10000") {
          var store = res.data.store;
          var userinfo = res.data.userinfo;
          that.setData({
            userinfo: userinfo,
            store: store
          })
        } else {
          that.showMsg(msg);
        }
        wx.hideLoading();   //隐藏加载loading
      }
    })
  },

  /***
   * 我的店铺
  */
  goPersonalStores:function(){
    this.goPage("../personalCenter/PersonalStores/PersonalStoresIndex/PersonalStoresIndex")
  },
  /***
   * 我的订单
  */
  goMyorder:function(e){
    var that = this;
    var state = e.currentTarget.dataset.state;
    this.goPage("../order/myOrder/myOrder?state=" + state)
  },
  /***
   * 提现申请
  */
  account: function () {
    this.goPage("../personalCenter/PersonalStores/putForward/putForwardRegin/putForwardRegin")
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.onLoad();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },
  goLogin: function () {
    this.goPage('../login/login')
  },
  /***
   * 合伙人跳转
  */
  partner:function(){
    this.goPage("../personalCenter/partner/partner")
  },
  /***
   * 关于我们
  */
  AboutUs:function(){
    this.goPage("../personalCenter/AboutUs/AboutUs")
  },
  /***
   * 设置跳转
  */
  set: function () {
    this.goPage('../personalCenter/set/set')
  },
  /***
   * 优惠劵跳转
  */
  coupon:function(){
    this.goPage("../personalCenter/coupon/coupon")
  },
  /***
   * 联系客服
  */
  service:function(){
    this.goPage('../personalCenter/service/service')
  },
  /***
   * 收藏
  */
  collect:function(){
    this.goPage('../personalCenter/mycollect/mycollect')
  },
  /***
   * 地址管理
  */
  receivingAddress:function(){
    this.goPage('../personalCenter/receivingAddress/receivingAddressList/receivingAddressList')
  },
  /***
   * 邀请好友
  */
  goinvitingFriends: function () {
    this.goPage("invitingFriends/invitingFriends")
  },
  /***
   * 邀请VIP
  */
  invitingVIP:function(){
    this.goPage('../personalCenter/invitingVIP/invitingVIP')
  },
  /**
 * 跳转页面
 */
  goPage: function (url) {
    wx.showLoading({
      title: '跳转中',
      icon: 'loading',
      mask: true
    })
    wx.navigateTo({
      url: url,
      success: function () {
        wx.hideLoading();
      }
    })
  },
  /**
   * 提示信息
   */
  showMsg: function (msg) {
    wx.showToast({
      title: msg,
      icon: 'none',
      duration: 2000,
      mask: true
    });
  },
})